// 角色接口
import httpInstance from '@/utils/http'

import { type userType, type roleType, type getRoleNameType } from '@/apis/model/userModel'
// 获取role数据
export const getRoleApi = () => httpInstance.get<any, roleType>('/user/getRole')

// 添加role数据
export const addRoleApi = (data: { roleName: string }) =>
  httpInstance.post('/user/addRole', data)
// 修改role数据
export const updateRoleApi = (data: { roleId: number; roleName: string }) =>
  httpInstance.post('/user/updateRole', data)
// 删除role数据
export const deleteRoleApi = (data: { roleId: number }) =>
  httpInstance.post('/user/deleteRole', data)
// 获取用户名称来当下拉框
export const getRoleNameApi = () =>
  httpInstance.get<any, getRoleNameType>('/user/getRoleName')

// 用户接口
// 获取user数据
export const getUserApi = () =>
  httpInstance.get<any, userType>('/user/getUser')
// 修改user数据
export const updateUserApi = (data: {
  name: string
  username: string
  id: number
  phone: string
  imgUrl: string
}) => httpInstance.post('/user/updateUser', data)
// 添加user数据
export const addUserApi = (data: {
  name: string
  username: string
  password: string
  phone: string
  imgUrl: string
}) => httpInstance.post('/user/addUser', data)
// 根据用户的角色名称筛选数据
export const filterUserDatarApi = (data: { name: string }) =>
  httpInstance.post<any, userType>('/user/filterUserData', data)
// 根据传来的id, 和密码来更改用户密码
export const setUserPwd = (data: { oldPwd: string, newPwd: string, id: number }) =>
  httpInstance.post('/user/setUserPwd', data)
